package com.xjoyt.pay.master.security;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Component;

@Component
public class PassportSecurity {

	private Map<Integer, AuthSecurity> securityMap;

	public PassportSecurity() {
		securityMap = new HashMap<>();
		securityMap.put(0, new SimpleAuthSecurity());
	}

	private AuthSecurity getAuthSecurity(int type) {
		if (securityMap.containsKey(type)) {
			return securityMap.get(type);
		}
		return securityMap.get(0);
	}

	/**
	 * 验证密码
	 * 
	 * @param password
	 * @param hex
	 * @return
	 */
	public boolean isSuccess(String password, PassportHex hex) {
		AuthSecurity authSecurity = getAuthSecurity(hex.type);
		return authSecurity.isSuccess(password, hex);
	}

	/**
	 * 加密密码
	 * 
	 * @param password
	 * @return
	 */
	public PassportHex createHex(String password) {
		int type = 0;
		AuthSecurity authSecurity = getAuthSecurity(type);
		PassportHex hex = authSecurity.createHex(password);
		hex.type = type;
		return hex;
	}
}
